package com.xb.loan.cashier.biz.pay.wechat;

import java.util.HashMap;
import java.util.Map;

/**
 * 微信支付错误码
 */
public enum WeChatErrorCode {
    
    NOAUTH("NOAUTH", "商户无此接口权限"),
    NOTENOUGH("NOTENOUGH", "余额不足"),
    ORDERPAID("ORDERPAID", "商户订单已支付"),
    ORDERCLOSED("ORDERCLOSED", "订单已关闭"),
    SYSTEMERROR("SYSTEMERROR", "系统错误"),
    APPID_NOT_EXIST("APPID_NOT_EXIST", "APPID不存在"),
    MCHID_NOT_EXIST("MCHID_NOT_EXIST", "MCHID不存在"),
    APPID_MCHID_NOT_MATCH("APPID_MCHID_NOT_MATCH", "appid和mch_id不匹配"),
    LACK_PARAMS("LACK_PARAMS", "缺少参数"),
    OUT_TRADE_NO_USED("OUT_TRADE_NO_USED", "商户订单号重复"),
    SIGNERROR("SIGNERROR", "签名错误"),
    XML_FORMAT_ERROR("XML_FORMAT_ERROR", "XML格式错误"),
    REQUIRE_POST_METHOD("REQUIRE_POST_METHOD", "请使用post方法"),
    POST_DATA_EMPTY("POST_DATA_EMPTY", "post数据为空"),
    NOT_UTF8("NOT_UTF8", "编码格式错误");
    
    private String errorCode;   // 错误码
    private String errorMsg;    // 错误描述
    private WeChatErrorCode(String errorCode, String errorMsg){
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }
    public String getErrorCode() {
        return errorCode;
    }
    public String getErrorMsg() {
        return errorMsg;
    }
    
    private static Map<String, WeChatErrorCode> codeBeanMap = new HashMap<String, WeChatErrorCode>();
    
    public static WeChatErrorCode getError(String errorCode){
        
        return codeBeanMap.get(errorCode);
    }
    
    public static String getErrorMsg(String errorCode){
        WeChatErrorCode wechat = codeBeanMap.get(errorCode);
        
        if(wechat == null){
            return "";
        }
        return wechat.getErrorMsg();
    }
    
    static{
        for(WeChatErrorCode obj : WeChatErrorCode.values()){
            
            codeBeanMap.put(obj.getErrorCode(), obj);
        }
    }
    
    public static void main(String[] args) {
        System.out.println(WeChatErrorCode.getErrorMsg("ILLEGAL_DYN_MD5_KEY123"));
    }
}
